package com.meida.module.bus.provider.handler;

import com.meida.common.base.entity.EntityMap;
import com.meida.common.mybatis.interceptor.PageInterceptor;
import com.meida.common.mybatis.model.PageParams;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.module.bus.client.entity.BusOrder;
import com.meida.module.bus.client.entity.BusOrderAppraise;
import com.meida.module.user.client.entity.AppUser;
import org.springframework.stereotype.Component;

/**
 * 后台订单评价列表
 */
@Component
public class BusOrderAppraisePageListHandler implements PageInterceptor<BusOrderAppraise> {

    @Override
    public void prepare(CriteriaQuery<BusOrderAppraise> cq, PageParams pageParams, EntityMap params) {
        cq.clear();
        String beginDate = params.get("beginDate");
        String endDate = params.get("endDate");
        cq.select(BusOrderAppraise.class, "appraiseId", "orderId", "appraiseUserId", "answerUserId", "score", "appraiseContent", "createTime");
        cq.select(AppUser.class, "userName", "nickName", "mobile");
        cq.select(BusOrder.class, "orderNo");
        cq.like(BusOrder.class, "orderNo");
        cq.like(AppUser.class, "userName");
        cq.like(AppUser.class, "mobile");
        cq.ge("DATE_FORMAT(orderAppraise.createTime,'%Y-%m-%d')", beginDate);
        cq.le("DATE_FORMAT(orderAppraise.createTime,'%Y-%m-%d')", endDate);
        cq.createJoin(BusOrder.class).setMainField("orderId").setJoinField("orderId");
        cq.createJoin(AppUser.class).setMainField("appraiseUserId").setJoinField("userId");
    }

}
